﻿using System;
using System.Collections.Generic;
using System.Data;
using BCL.Entity;
using NazSoft.Framework;
using System.Linq;

namespace BCL.Repository
{
    public class LookUpRepository
    {

        public List<LookUp> GetLookUp(string code)
        {
            String cacheKey = "Menu_" + code;
            var data = CacheHelper.Get<List<LookUp>>(cacheKey);

            if (data == null)
            {
                data = GetLookUpFromDatabase(code);
                CacheHelper.Add(data, cacheKey);
            }

            return data;
        }

        public List<LookUp> GetLookUpFromDatabase(string code)
        {
            object[] objName = { "Code" };
            object[] objValue = { code };

            SqlHelper helpclass = new SqlHelper();
            DataTable dataTable = helpclass.GetDataTable("Get_LookUpByCode", objName, objValue);
            var lstLookup = CollectionHelper.ConvertTo<LookUp>(dataTable).ToList();

            return lstLookup;
        }
    }
}
